import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);
 //访问登录页面
const routes = [
    {
        path: '/',
        redirect: '/index'
    },

    {
        path: '/login',
        name: 'login',
        component: () => import('@/views/Login')
    },

    //主页
    {
        path: '/index',
        component: () => import('@/views/Index'),
        children: [
            {
                path: '/',
                name: 'index',
                component: () => import('@/views/manager/Home'),
            },
            {
                path: 'users',
                component: () => import('@/views/manager/Users'),
            },
            {
                path: 'carousel',
                component: () => import('@/views/manager/Carousel'),
            },
            {
                path: 'add-carousel',
                component: () => import('@/views/manager/AddCarousel'),
            },
        ]
    },
    // 404 路由
    {
        path: '/*',
        redirect: '/index'
    }
]

//报错提示
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch((err) => err);
};

//创建路由
const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

//导出
export default router;